package br.com.mmm.javacenter.framework.reflection.injectors;

import br.com.mmm.autocenter.fornecedores.entity.TipoContato;
import br.com.mmm.javacenter.framework.annotations.InjectorComponent;
import br.com.mmm.javacenter.framework.dao.RepositoryBase;
import br.com.mmm.javacenter.framework.reflection.ReflectionFacade;

@InjectorComponent({
	TipoContato.class
})
public class TipoContatoInjector implements Injector{
	private RepositoryBase<TipoContato> repository;
	
	public void inject(ReflectionFacade rf, String field, Object value) {
		TipoContato tipoStatus = new TipoContato();
		if(value.toString().contains("-")){
			String[] split = value.toString().split("-");
			tipoStatus.setId(Long.parseLong(split[0]));
			tipoStatus.setTipoContato(split[1]);
		}else{
			tipoStatus.setId(Long.parseLong(value.toString()));
		}
		repository.klass(TipoContato.class);
		rf.set(field, repository.consultaPorCodigo(tipoStatus.getId()));
	}

	public RepositoryBase<TipoContato> getRepository() {
		return repository;
	}

	public void setRepository(RepositoryBase<TipoContato> repository) {
		this.repository = repository;
	}
	
}
